package top.hours48.ddbearapi.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.hours48.ddbearapi.handler.SessionHandler;
import top.hours48.ddbearapi.model.session.LoginReq;
import top.hours48.ddbearapi.model.session.UserMO;




@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/session")
public class SessionController {
    Logger logger = LoggerFactory.getLogger(SessionController.class);

    @Autowired
    private SessionHandler sessionHandler;

    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json")
    public UserMO login(@RequestBody LoginReq reqBody,
                        HttpServletRequest servletRequest, HttpServletResponse servletResponse) {

        UserMO userMO = sessionHandler.login(reqBody.getUserName(), reqBody.getPassword());

        return userMO;
    }


}
